@extends('layouts.admin')

@section('admin-content')
    @if (count($errors) > 0)
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
    <div class="box">
        <form id="login-form" action="{{url('user/'.$user->id)}}" method="post">
            <div class="form-group field-name required has-success">
                <label class="text-right" for="name">{{ trans("labels.user.name") }}:</label>
                <input type="text" id="name" class="form-control" name="name" value="{{$user->name}}">
                <div class="help-block"></div>
            </div>
            <div class="clearfix"></div>
            <div class="form-group field-email required">
                <label class="text-right" for="email">{{ trans("labels.user.email") }}:</label>
                <input type="text" id="email" class="form-control" name="email" value="{{$user->email}}">
                <div class="help-block"></div>
            </div>
            <div class="clearfix"></div>
            <div class="form-group field-password required">
                <label class="text-right" for="password">{{ trans("labels.user.password") }}:</label>
                <input type="password" id="password" class="form-control" name="password" value="{{$user->password}}">
                <div class="help-block"></div>
            </div>
            <div class="clearfix"></div>
            <div class="form-group field-role required">
                <label class="text-right" for="role">{{ trans("labels.user.role") }}:</label>
                <select id="role" class="form-control" name="role">
                    <option @if($user->role === config('constants.user.role.deployer')) selected
                            @endif value="{{ config('constants.user.role.deployer') }}">{{ trans("strings.user.role.".config('constants.user.role.deployer')) }}</option>
                    <option @if($user->role === config('constants.user.role.manager')) selected
                            @endif value="{{ config('constants.user.role.manager') }}">{{ trans("strings.user.role.".config('constants.user.role.manager')) }}</option>
                </select>
                <div class="help-block"></div>
            </div>
            <div class="clearfix"></div>
            <div class="form-group">
                <label class="text-right" for="status">{{ trans("labels.user.status_form") }}:</label>
                <input id="status" type="checkbox"/>
                <div class="help-block"></div>
            </div>
            <div class="box-footer">
                {{ csrf_field() }}
                <input type="hidden" name="_method" value="PATCH">
                <input type="hidden" name="id" value="{{$user->id}}"/>
                <input type="hidden" name="status" id="hid-status" value=""/>
                <input type="submit" class="btn btn-primary" value="{{ trans("crud.submit") }}">
            </div>
        </form>
    </div>
@endsection

@section("admin-js")
    <script src="{{ asset('js/icheck.min.js') }}"></script>
    <script type="text/javascript">
        $(function () {
            var statusObj = $('#status');
            var hidStatus = $('#hid-status');
            statusObj.iCheck({
                checkboxClass: 'icheckbox_minimal-grey',
                radioClass: 'iradio_minimal-grey',
                increaseArea: '20%' // optional
            });
            statusObj.on('ifChecked', function(event){
                hidStatus.val("{{config("constants.user.status.active")}}");
            });
            statusObj.on('ifUnchecked', function(event){
                hidStatus.val("{{config("constants.user.status.ban")}}");
            });

            @if($user->status == config("constants.user.status.active"))
                statusObj.iCheck('check');
            @endif
        });
    </script>
@endsection